package com.mainbo.androidframework.base.receivers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.view.Gravity;

import com.mainbo.androidframework.App;
import com.mainbo.androidframework.R;
import com.mainbo.androidframework.utils.LogUtil;
import com.mainbo.androidframework.utils.ToastUtils;


/**
 * Created by lsmtty on 2016/3/26.
 */
public class NetStateReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String TAG = NetStateReceiver.class.getSimpleName();
        ConnectivityManager manager = (ConnectivityManager) App.mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeInfo = manager.getActiveNetworkInfo();
        if(activeInfo==null){
            ToastUtils.showToast(context, App.mContext.getString(R.string.netstate_disconnection), Gravity.CENTER, 800);
        }
        else if(!activeInfo.isAvailable()){
            ToastUtils.showToast(context,App.mContext.getString(R.string.netstate_unuseful),Gravity.CENTER,800);
        }
        else {
            LogUtil.i(TAG, "active:" + activeInfo.getTypeName());
        }
    }
}
